<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/12/29 21:23:59 $)
// $RCSfile: rss_view.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./modules/knowledgebase/functions_knowledgebase.php");
require_once ("./modules/knowledgebase/functions_clientkb.php");
require_once ("./includes/functions_users.php");
require_once ("./includes/functions_xml.php");
require_once ("./includes/functions_comments.php");
$template->loadLanguageSection("knowledgebase");
$xml = new XML;

if ($_SWIFT["settings"]["kb_enrss"] != 1)
{
	exit;
}

if (empty($_GET["kbcategoryid"]))
{
	$_kbcategoryid = 0;
} else {
	$_kbcategoryid = intval($_GET["kbcategoryid"]);
}

$_kbcategory = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."kbcategories` WHERE `kbcategoryid` = '". intval($_GET["kbcategoryid"]) ."';");
if (empty($_kbcategory["kbcategoryid"]) && $_kbcategoryid != 0)
{
	// No such category
	exit;
}

$kbfuncresult = getSubCategories($_kbcategoryid, true);
$articlelist = $kbfuncresult["parentkbarticlelist"];

$xml->addParentTag("rss", array("version" => "2.0"));
	$xml->addParentTag("channel");
		$xml->addTag("title", sprintf($_SWIFT["language"]["rsskb"], $_kbcategory["title"]));
		$xml->addTag("link", $_SWIFT["swiftpath"]."index.php?_m=knowledgebase&_a=view&parentcategoryid=".intval($_kbcategoryid));
		$xml->addTag("description", sprintf($_SWIFT["language"]["rsskbdesc"], $_SWIFT["settings"]["general_companyname"]));
		$xml->addTag("language", $_SWIFT["adminlanguage"]);
		$xml->addTag("copyright", $_SWIFT["settings"]["general_companyname"]);

		foreach ($articlelist as $key=>$val)
		{
			$xml->addParentTag("item");
				$xml->addTag("title", $val["subject"]);
				$xml->addTag("link", $_SWIFT["swiftpath"]."index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=". intval($val["kbarticleid"]));
				$xml->addTag("description", $val["contents"]);
			$xml->endParentTag("item");
		}

	$xml->endParentTag("channel");
$xml->endParentTag("rss");

header("Content-Type: text/xml".SWIFT_CRLF);
echo $xml->returnXML();
?>